package com.huawei.appgallery.agwebview.api.delegate;

import android.app.Activity;
import android.content.Context;
import android.graphics.Bitmap;
import android.webkit.CookieManager;
import android.webkit.CookieSyncManager;
import android.webkit.WebChromeClient;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.LinearLayout;
import com.huawei.appgallery.agwebview.api.ui.IWebViewActivityProtocol;
import java.lang.ref.WeakReference;
import java.util.Map;
import o.azg;
import o.azh;
import o.azk;
import o.azm;
import o.azo;
import o.azq;
import o.azt;
import o.azu;
import o.azx;
import o.bab;
import o.bah;
import o.bar;
import o.bat;
import o.AccountBussinessListener;
import o.ccp;
import o.Logger;
import o.dof;
import o.enx;
import o.eoj;
import o.esy;

public class GeneralWebViewDelegate extends azq implements AccountBussinessListener, azo {
    private static Class<? extends azm> ʾ = null;
    private static Class<? extends bah> ˈ = null;
    private static Class<? extends azk> ˉ = null;
    private static Class<? extends azx> ˊˋ = null;
    protected azk ʼॱ = null;
    private String ˊˊ;
    private azm ˋˊ = null;

    static class d implements Runnable {
        private WeakReference<GeneralWebViewDelegate> ˋ;
        private WeakReference<Context> ˏ;

        public d(Context context, GeneralWebViewDelegate generalWebViewDelegate) {
            this.ˏ = new WeakReference(context);
            this.ˋ = new WeakReference(generalWebViewDelegate);
        }

        public void run() {
            Context context = (Context) this.ˏ.get();
            GeneralWebViewDelegate generalWebViewDelegate = (GeneralWebViewDelegate) this.ˋ.get();
            if (context == null || generalWebViewDelegate == null) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", "AccountResultRunnale context or delegate null");
                return;
            }
            CookieSyncManager.createInstance(context);
            CookieManager.getInstance().removeAllCookie();
            CookieSyncManager.getInstance().sync();
            generalWebViewDelegate.ˊॱ();
        }
    }

    public class e extends o.azq.e {
        final /* synthetic */ GeneralWebViewDelegate ˏ;

        protected e(GeneralWebViewDelegate generalWebViewDelegate) {
            this.ˏ = generalWebViewDelegate;
            super(generalWebViewDelegate);
        }

        public boolean shouldOverrideUrlLoading(WebView webView, String str) {
            if (Logger.ˎ()) {
                azh.ˏ.ˋ("GeneralWebViewDelegate", "shouldOverrideUrlLoading, url:" + enx.ॱ(str));
            }
            if (this.ˏ.ˋˊ != null && this.ˏ.ˋˊ.ˎ(this.ˏ.ˏॱ(), webView, str)) {
                return true;
            }
            if (this.ˏ.ʽॱ == null) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", " super.shouldOverrideUrlLoading(webview, url)");
                return super.shouldOverrideUrlLoading(this.ˏ.ʼ, str);
            } else if (this.ˏ.ʽॱ.ˎ(this.ˏ.ˏॱ(), webView, str)) {
                return true;
            } else {
                this.ˏ.ʽ(str);
                return true;
            }
        }

        public void onPageStarted(WebView webView, String str, Bitmap bitmap) {
            super.onPageStarted(webView, str, bitmap);
            if (this.ˏ.ˋˊ != null) {
                this.ˏ.ˋˊ.ॱ(this.ˏ.ˏॱ(), webView, str, this.ˏ.ˊˊ, this.ˏ.ͺ);
            }
        }

        public void onPageFinished(WebView webView, String str) {
            super.onPageFinished(webView, str);
            if (this.ˏ.ˋˊ != null) {
                this.ˏ.ˋˊ.ˊ(this.ˏ.ˏॱ(), str, this.ˏ.ͺ);
            }
        }
    }

    public static void ˎ(Class<? extends azx> cls) {
        ˊˋ = cls;
    }

    public static void ॱ(Class<? extends azm> cls) {
        ʾ = cls;
    }

    public static void ˊ(Class<? extends bah> cls) {
        ˈ = cls;
    }

    public static void ˏ(Class<? extends azk> cls) {
        ˉ = cls;
    }

    private void ˋᐝ() {
        if (ʾ != null) {
            try {
                this.ˋˊ = (azm) ʾ.newInstance();
            } catch (Exception e) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", "create IWebViewListener error");
            }
        }
    }

    private void ˎˎ() {
        if (ˈ != null) {
            try {
                this.ʽॱ = (bah) ˈ.newInstance();
                this.ʽॱ.ˎ((azo) this);
                this.ʽॱ.ˊ((azt) this);
                this.ʽॱ.ˊ(ˉ());
                this.ʽॱ.ˋ(ʽॱ());
                this.ʽॱ.ˏ(ˋˊ());
            } catch (Exception e) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", "create WebViewLoadPolicy error");
            }
        }
    }

    protected bab ˋˊ() {
        return new bab();
    }

    private void ˌ() {
        if (ˉ != null) {
            try {
                this.ʼॱ = (azk) ˉ.newInstance();
            } catch (Exception e) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", "create webViewAgent error");
            }
        }
    }

    public void ॱ(Context context, IWebViewActivityProtocol iWebViewActivityProtocol) {
        super.ॱ(context, iWebViewActivityProtocol);
        eoj.ˋ().ˎ("GeneralWebViewDelegate", this);
        ˋᐝ();
        ˎˎ();
        ˌ();
        ˏˎ();
        if (this.ˋˊ != null) {
            this.ˋˊ.ॱ(ˏॱ());
        }
    }

    private void ˏˎ() {
        if (ˊˋ != null) {
            try {
                ˎ((azx) ˊˋ.newInstance());
            } catch (Exception e) {
                azh.ˏ.ˏ("GeneralWebViewDelegate", "create IWebViewListener error");
            }
        }
    }

    public void ˏ(LinearLayout linearLayout) {
        super.ˏ(linearLayout);
        if (this.ˋˊ != null) {
            this.ʽ = this.ˋˊ.ˎ(ˏॱ(), linearLayout);
        }
    }

    public void ˋ() {
        super.ˋ();
        this.ʼ.setWebViewClient(ˊˋ());
        this.ʼ.setWebChromeClient(ˊˊ());
    }

    protected WebChromeClient ˊˊ() {
        return new a(this);
    }

    protected WebViewClient ˊˋ() {
        return new e(this);
    }

    public void ʽ(String str) {
        this.ॱˊ = 1;
        this.ˊˊ = str;
        if (this.ʻ != null) {
            this.ʻ.setIndeterminate(false);
        }
        if (this.ʽॱ == null) {
            azh.ˏ.ˊ("GeneralWebViewDelegate", "webViewLoadPolicy null");
            return;
        }
        this.ʽॱ.ˊ(ˏॱ(), this.ʼ, str, this.ॱˎ, this.ᐝॱ);
    }

    public void onAccountBusinessResult(ccp o_ccp) {
        if (o_ccp.ˎ == 103) {
            this.ͺ.post(new d(ˏॱ(), this));
        }
    }

    public void ʻ(String str) {
        if (this.ʽॱ != null && (this.ˊ instanceof Activity) && this.ˋ != null) {
            this.ˋ.ˏ(this.ॱᐝ);
            if (this.ˋ.ˋ()) {
                this.ˋ.ˊ(null);
            }
            this.ʽॱ.ˋ(this.ˊ, this.ॱ, this.ˋ);
        }
    }

    public void ʿ() {
        if (this.ˋˊ != null) {
            this.ˋˊ.ˊ(ˏॱ());
        }
        if (this.ʽॱ != null) {
            this.ʽॱ.ˎ(ˏॱ());
        }
        eoj.ˋ().ˊ("GeneralWebViewDelegate");
        super.ʿ();
    }

    public String ॱॱ() {
        if (this.ʼॱ != null) {
            return this.ʼॱ.ॱ();
        }
        return super.ॱॱ();
    }

    public void ˊ(int i) {
        ॱ(i);
    }

    public void ˎ(String str) {
        this.ॱˊ = 2;
        ॱ(1000);
        esy.ˊ(enx.ॱ(str), "1001");
    }

    public void ˋ(String str) {
        if (!dof.ˋ(str) && this.ˋˊ != null) {
            this.ˋˊ.ॱ(this.ˊ, str);
        }
    }

    public void ˎ(Object obj) {
    }

    public void ॱ(String str) {
        if (!dof.ˋ(str)) {
            ʽ(str);
        }
    }

    public boolean ˉ() {
        return false;
    }

    public String ˊᐝ() {
        return this.ˊˊ;
    }

    public WebView ˍ() {
        return this.ʼ;
    }

    public String ʾ() {
        return "GeneralWebViewDelegate";
    }

    public void ॱˊ(String str) {
        this.ͺ.post(new 5(this, str));
    }

    public String ˋˋ() {
        if (this.ʼ != null) {
            return this.ʼ.getUrl();
        }
        return null;
    }

    public void ˏ(String str, String str2) {
        this.ॱˊ = 1;
        this.ˊˊ = str;
        if (this.ʽॱ != null) {
            this.ʽॱ.ˋ(str, str2);
        }
    }

    public boolean ˎ(WebView webView) {
        return azg.ˊ(webView);
    }

    public String ˏ(Context context) {
        return bar.ˊ(context);
    }

    public boolean ˏॱ(String str) {
        return bar.ˋ(str);
    }

    public boolean ˋॱ(String str) {
        return bar.ˏ(str);
    }

    public String ˎ(Context context) {
        return bar.ˋ(context);
    }

    public Map<String, String> ˊॱ(String str) {
        return bar.ॱ(str);
    }

    public void ˎ(azu o_azu) {
        bar.ˊ(o_azu);
    }

    public void ॱ(String str, String str2, String str3, String str4) {
        if (this.ˊ == null || this.ʼ == null) {
            azh.ˏ.ˏ("GeneralWebViewDelegate", "getPostData error context or webview");
        } else if (dof.ॱ(str) || !("JSON".equals(str4) || "KV".equals(str4))) {
            azh.ˏ.ˏ("GeneralWebViewDelegate", "getPostData param error");
        } else if (ˏॱ(str)) {
            if (Logger.ˎ()) {
                azh.ˏ.ˋ("GeneralWebViewDelegate", "getPostData url:" + enx.ॱ(str) + ";postDataType:" + str4);
            }
            o.bau.d dVar = new o.bau.d();
            dVar.ˎ(str);
            dVar.ˋ(str2);
            dVar.ˏ(str3);
            dVar.ॱ(str4);
            dVar.ˏ(ˋˊ());
            bar.ˏ(this.ˊ, this.ʼ, dVar);
        } else {
            azh.ˏ.ˏ("GeneralWebViewDelegate", "getPostData url not INTERNAL");
        }
    }

    public void ˎ(Context context, String str, String str2) {
        new bat().ˋ(context, str, str2);
    }
}
